﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

namespace DataAccess
{
    public class CourseData
    {
        public DataTable GetCurrentClassRooms(int week, int time)
        {
            DataTable dt = new DataTable();
            Database database = DatabaseFactory.CreateDatabase();
            string sqlCommand = "GetClassRoomsByTime";
            DbCommand dbCommand = database.GetStoredProcCommand(sqlCommand);
            database.AddOutParameter(dbCommand, "@AffectRows", DbType.Int32, 10);
            database.AddInParameter(dbCommand, "@cWeek", DbType.Int32, week);
            database.AddInParameter(dbCommand, "@cTime", DbType.Int32, time);
            dt = database.ExecuteDataSet(dbCommand).Tables[0];
            return dt;      
        }

        public DataTable GetCurrentCrByCode(int week, int time,int crCode)
        {
            DataTable dt = new DataTable();
            Database database = DatabaseFactory.CreateDatabase();
            string sqlCommand = "GetCurrentCRByCode";
            DbCommand dbCommand = database.GetStoredProcCommand(sqlCommand);
            database.AddOutParameter(dbCommand, "@AffectRows", DbType.Int32, 10);
            database.AddInParameter(dbCommand, "@cWeek", DbType.Int32, week);
            database.AddInParameter(dbCommand, "@cTime", DbType.Int32, time);
            database.AddInParameter(dbCommand, "@crCode", DbType.Int32, crCode);
            dt = database.ExecuteDataSet(dbCommand).Tables[0];
            return dt;
        }
        public int GetStuCountByCourseID(int courseID)
        {
            DataTable dt = new DataTable();
            Database database = DatabaseFactory.CreateDatabase();
            string sqlCommand = "GetStuCountByCourseID";
            DbCommand dbCommand = database.GetStoredProcCommand(sqlCommand);
            database.AddOutParameter(dbCommand, "@AffectRows", DbType.Int32, 10);
            database.AddInParameter(dbCommand, "@courseID", DbType.Int32, courseID);            
            dt = database.ExecuteDataSet(dbCommand).Tables[0];
            return Convert.ToInt32(dt.Rows[0]["StuCount"]);
        }
    }
}
